Module-level declarations

Properties

Link copied to clipboard
val ACCOUNT_TYPE_LOCK: text = "FT4_LOCK"

When an account entity has this as its type field, it is a lock account

A lock account is like a safe where tokens are put when the users should not be able to access them. This is useful, for example, when the users have staked those tokens or they are participating in an auction where they have put a bid for a certain amount of tokens.

In both cases, the users are still the owners of the assets, but they're not allowed to use them.

An account_link entity is created that holds the relevant information:

  • account: the account that owns the asset

  • secondary: the lock account

  • type: the purpose of the locking (e.g. "staking", or "auction")

Functions

Link copied to clipboard
function ensure_lock_account(type: text, account: account): account

Retrieves the lock account given an account and the lock type. Creates the account if it does not exist.

Can only be called from an operation.

Link copied to clipboard
function get_lock_account_id(account: account, type: text): byte_array

Computes the id that the lock account will have given the account and the type.

Link copied to clipboard
function get_lock_accounts(account: account): list<(type: text, account: account)>

Gets all existing lock accounts for the provided account

Link copied to clipboard
function get_lock_accounts_with_non_zero_balances(account: account): list<(type: text, account: account)>

Gets existing lock accounts for the provided account where some assets have been locked

Link copied to clipboard

Retrieves the total locked sum of the specified asset over various lock types, given the account that locked them. The returned value adds up the values that were locked, regardless of the lock type, for a single asset.

Link copied to clipboard
function get_locked_asset_aggregated_balances(account: account, types: list<text>?, page_size: integer?, page_cursor: text?): list<pagination_result>

Similar to get_locked_asset_aggregated_balance, except that it allows retrieving the info for all locked assets.

Link copied to clipboard
function get_locked_asset_balance(account: account, asset: asset, types: list<text>?, page_size: integer?, page_cursor: text?): list<pagination_result>

Retrieves all balances of a certain asset that were locked from a certain account. Paginated, the returned data is a list of tuples containing the amount and a lock type label: list<(lock type, amount)>

Link copied to clipboard
function get_locked_asset_balances(account: account, types: list<text>?, page_size: integer?, page_cursor: text?): list<pagination_result>

Similar to get_locked_asset_balance, except that it allows retrieving the info for all locked assets.

Link copied to clipboard
function lock_asset(type: text, account: account, asset: asset, amount: big_integer)

Transfers an asset to the lock account, rendering it inaccessible to the user.

Can only be called from an operation.

Throws if the required assets cannot be moved. Common cases include:

  • the amount to transfer is not in the accepted range (0, 2^256) (exclusive)

  • some conditions added in development through transfer extensions (before_transfer or after_transfer) aren't met

  • the account's balance is lower than amount

Link copied to clipboard
function unlock_asset(type: text, account: account, asset: asset, amount: big_integer)

Retrieves an asset from the lock account back to the specified account. Note that this function does not perform any authorization before moving the assets; users should thus not be given direct access to this function.

Can only be called from an operation.

Throws if the required assets cannot be moved. Common cases include:

  • the amount to transfer is not in the accepted range (0, 2^256) (exclusive)

  • some conditions added in development through transfer extensions (before_transfer or after_transfer) aren't met

  • the lock account's balance is lower than amount, which means there's less locked tokens than what is being unlocked